/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.vcforms.view.component;

import java.awt.Font;
import org.opu.vcforms.editor.EditViewFactory;
import org.opu.vcforms.editor.SingletonEditViewFactory;
import org.opu.vcforms.editor.TabbedEditViewFactory;
import org.opu.vcforms.io.Logger;

/**
 *
 * @author yura
 */
public class EditProperties extends ButtonView {

    public static final String EDITOR_TYPE_LABLE = "edit";
    public static final String PRINT_LABLE = "print";
    public static final String FONT_LABLE = "font";
    public static final String MAXIMAL_FILE_SIZE_LABLE = "max-file-size";

    public static final int SINGLETON_TYPE = 0;
    public static final int TABDED_TYPE = 1;
    public static final String NULL = "null";
    
    private String printCommand = NULL;
    private int editType = TABDED_TYPE;
    private int maximalFileSize = 16384;//16kb

    private EditViewFactory viewFactory;
    private Font font;

    public EditProperties(GUIProperties prop) {
        super(prop);
        viewFactory = createViewFactory();
        font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
    }

    @Override
    protected ButtonProperties getProp() {
        return ButtonProperties.getDefaultEditToolbarButtonProperties();
    }

    @Override
    public String getClassName() {
        return "Edit-toolbar";
    }

    public String getPrintCommand() {
        return printCommand;
    }

    public Font getFont() {
        return font;
    }

    public void setPrintCommand(String printCommand) {
        propertyChange(PRINT_LABLE, this.printCommand, printCommand);
        this.printCommand = printCommand;
    }

    public void setEditType(int editType) {
        if (editType > TABDED_TYPE || editType < SINGLETON_TYPE){
            Logger.error(getClass().getName() + ": Wrong edit type: " + editType);
            return;
        }
        propertyChange(EDITOR_TYPE_LABLE, this.editType, editType);
        this.editType = editType;
        this.viewFactory = createViewFactory();
    }

    public void setFont(Font font) {
        propertyChange(FONT_LABLE, this.font, font);
        this.font = font;
    }

    public int getMaximalFileSize() {
        return maximalFileSize;
    }

    public void setMaximalFileSize(int maximalFileSize) {
        propertyChange(MAXIMAL_FILE_SIZE_LABLE, this.maximalFileSize, maximalFileSize);
        this.maximalFileSize = maximalFileSize;
    }

    public EditViewFactory createViewFactory(){
        switch (editType) {
            case TABDED_TYPE:
                return new TabbedEditViewFactory();
            case SINGLETON_TYPE:
            default:
                return new SingletonEditViewFactory();
        }
    }

    public EditViewFactory getViewFactory() {
        return viewFactory;
    }
}
